const express = require('express')
const app  = express()
const bodyParser = require('body-parser')
const Router = require('./Router')
const tokenRules = require('./token/tokenRules')
const fs = require('fs')
const path = require('path')
const cors = require('cors')
const api2 = require('./api2')
const api3 = require('./api3')

const session = require('express-session');
app.use(session({
    secret: 'luckystar',
    name: 'captcha',
    resave: false,
    saveUninitialized: true,
    cookie: { maxAge: 50000 },
    rolling: true,
  }));


// 时间
function setTime(){
    let current = new Date().valueOf()
    let c1 = Date(current)
    console.log('server running 3000');
    console.log(c1);
}


/* 导入解析 */
app.use(cors())
app.use(bodyParser.urlencoded({extended:true}))
app.use(bodyParser.json())

/* pubilc */
app.use('/public',express.static(path.join(__dirname,'public')))

app.use('*',(req,res,next)=>{
    tokenRules(req,res,next)
})

/* 挂载 */
app.use('/api',Router)
app.use('/api',api2)
app.use('/api',api3)


/* 一级路径 */
app.get('/',(req,res)=>{
    // res.writeHead(200,{"Content-Type":"text/html"})

    // fs.readFile('./menus/index.html','utf-8',(err,data)=>{
    //     if(err){
    //         res.send('读取文件失败')
    //     }else{
    //         res.end(data)
    //     }
    // })
    res.send('链接成功')
})

app.listen('3000',()=>{
     setTime()
})